refactored javascript file