runtime: Move more setup logic into lib/ui.c, prettify tests a bit more