Correct bug in applyThreshold, compatibility with more data types