A better way to use localStorage and sessionStorage