added phase3 and eccheck, may need verificaiton on correctness