Improved performance on large inputs