Fix some wellformedness issues

Also fixed some duplicate IDs reported by Mats Erik Andersson.