Properly handle empty lists
Handle empty keys, but it's not perfect