Fix incorrect var use.
Rewrite `expand` to be more thorough and correct dep maps.