Added status codes to errors.
Cleaned up code.