tested.
Made functions be static.
flushed the output stream.