Make use of the dict capabilities to simplify some variables management. Also put the local function calls on top, to deduplicate them, making sure we don't even attempt to rebuild the same artifacts.