DRYed up some JS