Completed flatten method