Major refactoring.

- DRY out localStorage actions.
- OOPize code.
- Put shared constructors in lib.js