added error handling code. reduced localStorage amount