changed to loopify before flattening