refactor debug switch