Fix 240

- fix the bug
- add a test
- remove stray debug prints.