Moved debug code into an if statement