Improved algorithm speed