serialize: various fixes and additions to unit test