Includes a bunch of changes and closes a number of issues on Github. Lots of refactoring.