added checks for invalid strings