Try setting MAX_CORES explicitly within function.