Rewrite the js to make a little more sense.