Unicode checking and fixed logic error