Quite a bit of cleanup.  Add in working WebSockets to have the interface update automatically.  If you dont have WebSockets, it falls back to polled XHR every 10 seconds.