Refactor dict-related codes