Update ui.js

Massive restructuring. Not yet functional.