Cleaned up javascript and made safe ('use strict', function enclosures, properly scoped accidental global variables, etc...