Fixes #16: guard against possible null pointer exceptions