Trying new implementation of flatten