refactored javascript

oohwee