Implement import and export of settings. Misc bugfixes & cleanup.