add nicer debug messages. Fix testcase