fixing detect bug