adding threshold function