Added a great many features and bug fixes

I hope the commits are descriptive enough to make clear what all has been changed.