fixed up error handling