fixed issue #515 and added test case for same