remove dead code and fix null bug