critical bugfix: invalid foreach