refactor Flattener