Moved most of JS code away from HTML.

Working on adding streams tree and sessions support