new version, fixed some NPE, fixed #2