Flatten array of objects correctly