Added some debug prints and a small fix for done flag