Add cleaner version of flattenAll