moved debug code to a better place