shorten flatten function, refine the tests