Refactor to only modify DOM once per row