Speed up unique ID generation, closes #655
merge 6737e377262f3fbb174e21e4cf91a3dd30ed1988