Fix potentially unclosed streams

Simplified some file checks
Code formatting and added copyright
Merge pull request #427 from yueh/development

Fix potentially unclosed streams