adding check for minimum length to avoid runtime exceptions