Remove unused code
Code cleanup

- Better code organization (no giant for loop in main)
- Fix some error handling
- Close files after processing with --dry-run

Fixes #7.
If no files are given, read filenames from stdin

Fixes #3.
Add a test of basic functionality
Clean up temp files if we encounter an error

Thanks to @tv42 for spotting.
Get rid of output during tests
merged upstream