cleaned up error handling