Fixing compiler warnings and optimizing refine_potential
More optimizations in refine potential
Optimizing the communication of state variables