fix some critical bugs