helper function to validate tags on elb

def _tags_present(name, tags, region, key, keyid, profile):
    '''
    helper function to validate tags on elb
    '''
    ret = {'result': True, 'comment': '', 'changes': {}}
    if tags:
        lb = __salt__['boto_elb.get_elb_config'](name, region, key, keyid, profile)

        tags_to_add = tags
        tags_to_update = {}
        tags_to_remove = []
        if lb.get('tags'):
            for _tag in lb['tags']:
                if _tag not in tags.keys():
                    if _tag not in tags_to_remove:
                        tags_to_remove.append(_tag)
                else:
                    if tags[_tag] != lb['tags'][_tag]:
                        tags_to_update[_tag] = tags[_tag]
                    tags_to_add.pop(_tag)
        if tags_to_remove:
            if __opts__['test']:
                msg = 'The following tag{0} set to be removed: {1}.'.format(
                        ('s are' if len(tags_to_remove) > 1 else ' is'), ', '.join(tags_to_remove))
                ret['comment'] = '  '.join([ret['comment'], msg])
                ret['result'] = None
            else:
                _ret = __salt__['boto_elb.delete_tags'](
                        name, tags_to_remove, region, key, keyid, profile)
                if not _ret:
                    ret['result'] = False
                    msg = 'Error attempting to delete tag {0}.'.format(tags_to_remove)
                    ret['comment'] = '  '.join([ret['comment'], msg])
                    return ret
                if 'old' not in ret['changes']:
                    ret['changes'] = salt.utils.dictupdate.update(ret['changes'], {'old': {'tags': {}}})
                for _tag in tags_to_remove:
                    ret['changes']['old']['tags'][_tag] = lb['tags'][_tag]
        if tags_to_add or tags_to_update:
            if __opts__['test']:
                if tags_to_add:
                    msg = 'The following tag{0} set to be added: {1}.'.format(
                            ('s are' if len(tags_to_add.keys()) > 1 else ' is'),
                            ', '.join(tags_to_add.keys()))
                    ret['comment'] = ' '. join([ret['comment'], msg])
                    ret['result'] = None
                if tags_to_update:
                    msg = 'The following tag {0} set to be updated: {1}.'.format(
                            ('values are' if len(tags_to_update.keys()) > 1 else 'value is'),
                            ', '.join(tags_to_update.keys()))
                    ret['comment'] = '  '.join([ret['comment'], msg])
            else:
                all_tag_changes = salt.utils.dictupdate.update(tags_to_add, tags_to_update)
                _ret = __salt__['boto_elb.set_tags'](
                        name, all_tag_changes, region, key, keyid, profile)
                if not _ret:
                    ret['result'] = False
                    msg = 'Error attempting to set tags.'
                    ret['comment'] = '  '.join([ret['comment'], msg])
                    return ret
                if 'old' not in ret['changes']:
                    ret['changes'] = salt.utils.dictupdate.update(ret['changes'], {'old': {'tags': {}}})
                if 'new' not in ret['changes']:
                    ret['changes'] = salt.utils.dictupdate.update(ret['changes'], {'new': {'tags': {}}})
                for tag in all_tag_changes:
                    ret['changes']['new']['tags'][tag] = tags[tag]
                    if 'tags' in lb:
                        if lb['tags']:
                            if tag in lb['tags']:
                                ret['changes']['old']['tags'][tag] = lb['tags'][tag]
        if not tags_to_update and not tags_to_remove and not tags_to_add:
            msg = 'Tags are already set.'
            ret['comment'] = '  '.join([ret['comment'], msg])
    return ret