Fixed bug #4 and added testcase for it