Algorithm updates, refactoring.