Refactoring suffix tree naive