moved illegal char checking to bottom