fix a few bugs
fix null pointer deref crash