fix undefined method `nil' error