remove flatten
tidy up.
remove dead code based on coverage.