Added a testcase for #165 and fixed #165.