Refactored the render method in UI.js

Sorry for indentation, editor was not cooperative