Added more flush and debug output