Refactor _render function