fix some compile/runtime bugs