Refined the renderCells function