add serialization code writen by HRY and fix code in tests