working for multi cores
quick fix
fixed up variable passing in nested functions
generalized back to working without ProcMaganer