slightly tidied munging method (still hacky)