Clean up and straighten error handling