added checks to test end of string when parsing string for a polynomial