moving some parts into functions and making it more simple so we can move it into chef-guard