This implementation seems highly inefficient.