Add more error codes, messages and error checking.

Same as above.