Changed the logic behind debugging and logging.