Deleted repeated code by moving some of the if statements to the function constructor.