added the parent update part of the algorithm