Improve widget state persistence