Adapted from Vladimir's suggestion. The switch default allows the pointer to be null at this point.