make flatten work and tested