Started work on the algorithm, sort of functional