Abstraction

This starts abstracting some common functions into something more separate from the UI - not fully implemented yet, but its far enough along that we've got a better CSV export for example. This also picks up a number of the open issues.