Changed most of the code to be a function