moved if statments into a funcion