fixes #15: Refactored and test suite passes