Factor the render func into a separate func.

This way the try/catch won't disable optimization of the entire function.