removed no longer used flatten function