factor out javascript from index