Refactoring of store code

* Only create an array of store items when necessary for the UI
* Refactor ui-store to have fewer globals (should increase future flexibility)
* Loads of other small cleanups, renamings, reformattings etc.