refactor : use first/lastObject instead of index