check for undefined before looping over arrays (fixes #71)