changed intentionWrapper from a global variable to an anonymous function