Correct a bug in primitives.py trail machinery