rewritting test code to flatten list