Had to switch if, else if, else statements to function