Refactoring ordered_dict to reuse linked-list code