opt: remove unused debug function and code, test a few more corner cases.