fixed issue with middle index method