gInitialPages -> window.gInitialPages

Also removed some redundant code lines