Doc Strings for most of the functions.

I've added as many doc strings as I found lacking. I ignored helper functions that only lived inside another function and anything with a comment indicating it was a hack. I also deleted some dead code.