Fixed some boolean errors, added some debug code