fixed bugs tresholds and add functions