fixed NPE
fixed tests