added while loops to ensure we find the true final size. This makes it pretty slow sometimes and need to find a smarter way to do it...