even added a try-catch block around access to localStorage and sessionStorage