Add a write_index method, avoid repetition