Refactor debug mode

The `--debug` flag is currently handled in two places.