Add 'flatten' function.