DRYing js code