Improve performance and remove dependency on iter