move check outside forEach loop

see #656