refactored javascript.