Changed getKeyWithFlag to return key info instead of id