fixed error NoMethodError: undefined method `last'