added flush functionality to see output at the same moment