Performance improvement by limiting calls to localStorage.getItem().