Fix bugs involving nil