Added debug, fixed bugs