Refactor codebase. Fix a bug in SettingsFragment.