Code to flatten a multilevel list