Started working on the actual algorithm