Added most of the last item comparison code, without actually using it, just to make sure existing code works