break out main function into a javascript file