Execute template into a buffer to avoid partial output and properly catch errors before writing

If executing the template straight into the ResponseWriter the output will be partial on error. Instead we should always write to a bytes.Buffer first and check for errors before actually writing the response.