Refactored javascript file