Add support for localStorage
Bring in some of @luigy's changes