Fixed a bug in the overlap function