Refactor and tests (closes #10)