Fixing an order of operations bug.

Also making the whole thing work without javascript since it’s so close
to that anyway.