A few quick fixes

Hao found a few problems in the code that fixes the non-convergence
problem.