Backport pavement.py from master