Fixing tests and guarding against NPEs