Improved performance by limiting calls to localStorage.getItem().