Threshold tests + refactoring