Rewrite to allow transparent ID generation.

Please review and merge.