fix some bugs, refactory some part of the source code.