Split into loader and main body

Run pinit_main.js only if it's not been run before.