fixes scope problem with one of the global vars after slight code redux