rewritten render method
refactoring and fixes