started moving the if statments into a function