Fixing undefined method for nil:NilClass