Finished some major refactoring of ui code.