refs #15. fixed some bugs.