Changed pMincapply so you can pass in global variables through the global arguement