add serialize spec and fix implementation