Add some nullptr checks