tidy main.js: move main() to top of file

Re-order 'main.js' so that it reads from more general to more specific
by moving 'main()' to the top of the file.