Avoids collisions and duplicates.