Restored debug output, and fixed console output flushing