Quite a few changes

Ok, so this is going to be a lot of changes. It would be best to look through the commit log to see what they all are. Basic behavior is preserved, though, and unit tests have been added to confirm this.