Attempting to fix the None error in the illegal character check