Refactor into class, methods, and tests

Please do not merge this pull request! It's for instruction & explanation.

This is a small refactor to start pulling code into a testable state. It's far from perfect but a start at breaking this out.