cleaning up error handling a bit