severe cleanup of javascript; still functions (needs more gui separation)