Created detector class to encapsulate the detect function. Significant speed up.