Repaired some bugs