removed cleanOutputBuffer, and cleaned up the way error templates are handled.