santize strings and fix error checking