optimized the each() loop