use writeSync instead of stdout.write to make sure that stream is flushed