Fix a bug that caused a NoMethodError on nil