Fixing bug with nested objects in array