code for higher order functions