move var and function to .js