fix several bugs