Convert to recursive
Added check to see if maxLength is set to a non-zero value