clean up error handling a bit