fixed "each" function