prevent some memory leak; re-design some of the classes