Add getListOfKeys, refactor duplicated code.