This could be refactored so that CApplicationMessenger::Get().LoadProfile(index) only appears once in the code by doing all the necessary checks (password etc) first and returning an error if one of them fails. If all is well at the very end we can call the LoadProfile() method to actually change the profile.