Modified to use functions as parameters