refactoring of render function