added flushing and closing of output streams.

don´t know if this makes any sence here but the lecture suggested to do it ;)