Moved all code into header files