Refactors the Ui JS file. To Be Continued [Unstable beacause of /js/ui.js:140]