Initial error handling refactor.
Minor changes to error handling.