Cleaned up, freed everything and got rid of valgrind errors and comple warnings.