Cleaned up the detector code