Speed up unique ID generation, closes #731