Functions 1

Getting rid of the spegetti code