Fix some bug and reduce not important code