Cleaning up some error handling