Add checks before trying to print debug messages