improved isBetween method