refactoring algorith recursions so we can reuse the definitions...