moved debug into if