Fix Bug 24 and add test cases for it