Fix lost errors and missing headers.

Had the wrong error variable name, so when an error happened, you got nil.