finish flatten basic functionalities