Some first changes to JS structure.
Move some JS around.