Refactoring, increasing robustness of thresholding and clapper detection