Write generateCells function