better implementation of dict_parent