Speed up unique ID generation, closes #731
merge 5d91b44dcdb96eb7f1bd14342d5b2a2b2da23271