Fixed a bug and created a test case.