Use higher order function to limit maximum number of calls