Added debug mode, and more code