Encapsulate stuff into main() function.

refs #133
Fix variable messup in jobname.

refs #130