code refactoring: starting the new algo