error handling was incorrect