refactored (for in) loops on arrays, fixes #2