Added check for end and beginning of the string
Fixed another case where the previous check passed