Added lowest common ancestor function