fixed error-related bug and added test for failing case