fix several bugs.