moved some if statements into functions.