implement threshold function