Fixed id assignment bugs.