Cleaning up code using functions