Changed some code to functions.