More flexible operations

- Add more command-line options
- Refactor out common file operations in its own file