Adding null pointer checks