Complete the algorithm