Using the builtin threshold function. How could I not have found it??