Add count property and optimize serialization