fixing .each call on undefined object