Function "flatten" completed