Factor out javascript into separate JS file