fixed issue #37 and added a test case for it