reduce running time and modify some function