move debugging output to common code