Added encode and decode functions for localstorage