Re-organized some of the code

Move declarations into header files for sharing.