FIX: some bugs in gram