changed anonymous functions to use smart references