Fixed NRE in some cases