Fix for issue#112, along with test case.