Fix count serialization

Fixes #1015