Refactor bestfitChunk and findBestfitChunk