big code simplification. all dictionaries have been removed as they're fiddly to manipulate. instead we're lists of tuples exclusively as they're much easier to work with. the file output code has been taken out of a function as we only call that code once.