fixed out of bound exception in shared_prefix function