Improved isPrefixFreeSet function