serious refactor/cleanup of the Javascript/UI code, this is a checkpoint commit, more still needs doing.