refactor
Algorithm running now working as expected.