Refactor rendering to be inside loop