Commented and refactored javascript file