Minor refactor

- Changed file extension
- Separated logic and data
- Added try/finally for cleanup
- Switched to env(1)
- Changed explicit variable boolean to flow control (break)