error handling bug fixes