added find middle function using counter.