Fix off by one error for last element index.