Add error checking when parsing string