added method to find middle index