Refactored UI javascript to be event based.