JS bits, and some minor template stuff

Some random stuff.
It should not break anything (well, not more than usual anyway).