Refactor debug logging into separate methods.