Implemented a first common ancestor algorithm