Refactor into a class

Per discussion in Issue #2.