Replaced all algorithms with optimized versions.