Refactored debug output, moved into tasks