updated collectFunction