fixing memory leaks and performance issues using xcode instruments.
Tried running mpi using profiler, didn't work.