make sure thread releases algo wait lock before it is cancelled, and some more debug output