fixed a bug and added a test case for it