Code refactoring. Cleaner &n simpler algorithm implementation