fix up several bugs