Minor refactoring and fixed a settings bug