finished new threshold function