#refs #8. Remove some unused source code, fixed some bugs.