now pretty much everything of the algorithm is working