Pre-allocate memory for variables

Each of the portions of code requiring intensive looping now have
pre-allocating memory to help speed things up.