could we pull as much of this as possible out into its own JS file?