fix NPE
several minor fixes