Added a flatten method