WFK2-600 update to JavaScript

I added some comments and more logging.

I refactored some of the javascript and fixed several bugs.