the algorithms works. now I just need to do some quick refractoring before I plug in a file input!