fix substitution filter
fix npe
fix more bugs