Functional implementation of getKeys (not tested)