added try/catch for .each()