handle error better
cleaned up error handling