Aggressive dead code elimination

Just a heads-up pull request, no where near ready to be merged. Started working on this feature just now so not very much done so far.

One thing that may be of interest is the build_graph function I added to util.py, this function can be used anywhere you need a graph and it makes sense to use the same code everywhere. I'll probably do a big refactoring pass once everything starts landing, though, since we're getting into a bit of a branch hell with me having two sizable feature branches and @wheybags having two, and only one out of four having been merged to master so far.