Refactor get_primary_keys