implemented better error checking for corrupted localstorage variables