Update to function

Changed the old code to a function. Because that is what it should be.