Restructured JS file to isolate variables