Numerous refactorings, bug fixes and new features.