refactored algorithm into smaller methods, fixed tests
Merge pull request #8 from CandidKilsborne/algorithm-refactor

refactored algorithm into smaller methods, fixed tests