Fix nil pointer on some situatuion