refactor and tests passing for localstorage.
refactored writeclient, tests passing