Speed up unique ID generation, closes #655