refactoring to reduce number of renders