Various improvements, bug fixes, reorganization