Rewrite the render function
Some minor changes