Add more NULL pointer checks