Made sure that all streams are closed after use. Added copyright header.