Added defensive null checks to repository (corrected).