added the code for selecting the lowest common ancestor