#24 small refactoring on algorithms, prepare to move to separate module