DRYed up .js file