Refactor cell code