guard against non-existant localStorage and sessionStorage