Move script to new file.
Bring over some template logic from the old site.