fix assertion
fix npe
fix #659