move debugging into a separate function, disable by default