Revised id assignment

Ids now assigned in a less confusing, less bug prone way.