Adding some extra protections against null exceptions.