added a testcase, and made some other changes