Added logic to save settings