Updated implementation: Don't check the HEAD in the iteration