Restructured code

C++ requires template code to all be in the same file to work properly