NPE fixed, tests added