Moved lots of UI stuff to ui.c.