Phase one functions
Clean up of code