Fixed bug in render method and code clean-up.