Simplify main() in desktop

A whole bunch of local helper functions.