Updated a bunch of functions moving code to .cpp and out of header files