Optimize/Cleanup

No idea what performance increase this will give, there will be one for creation though. There are also optimizations throughout that will give slight speed increases and protect against falsey compares.
Alright, misread this part of the code. Moving the multiple function declarations outside of the for loop is a must, but the scope is broken this way. I'll revise that and fix the scope.