some more javascript refactoring.