issue#813 Added new testcase, fixed bug