started implementing the algorithm