NPE fixed, test added