Core-UI split work

This one is a bit messy.  Main aims:
* Split obviously UI stuff out from 'non-UI' files (though as always this is thoroughly incomplete)
* Fix some bugs found (tests to come in another request)
* Get tests working properly on OS X