smarter size algorithm