Pulled out some bits into a JS file