Fixed some gap detecting issues