First draft at making auto-increment more general.