Fix ordering of JS functions