Added try { … } catch for localStorage access