Fix for issue#342, added new test cases