fixed a bug, and added a test case