fixed several bugs.