refactor main.py, flesh out functions from main function

@stdweird, @wpoely86: please review?

The diff is going to look a bit messy, maybe you want to look at the actual new `main.py` instead...
ok, override is maybe not the right term here... it boils down to having two ways of making `resolve_dependencies` retain all dependencies, either via the build option, or the named argument; by default both are `False`, putting either to `True` makes it retain all dependencies

I'll add a comment to clarify this.