move flush() after every write(s) from console to terminal