check for string length and improve error messages