completed creating the algorithm