almost finished reading the implementation of the algorithm