Added support for threshold using functions