refactoring of render method