Solved some bugs from ecorr.cpp