Prevent NPE by more checks

Should not be really a problem after
db ref. integrity improvement (FK)