Implementation without hashset