Add deserialize function
Fix off by one