fix a bug and modify the overlap function