Restructured Functions

Moved a lot of functions around, optimized some arrays to pointers.