handle state changes and make becamemaster return to clear config