more restructuring for better encapsulation of javascript