fix several bugs..