fix an issue with indexing by gid/aid. also add a lookup mechanism.