Fixed iterating over an object with foreach