Added more checks for string overflow.