Refactor localStorage code a bit