Cleaned up error handling a bit