adding a guard to fix occasional NPE - fixes #800