Add flatten method