Reimplemented applyOperator function to use a case statement.