Refactor of names, logic. Added write_cells function