add a simple testcase and fix the bugs it showed