Introduce gid for messages

Also rename global counters