Fixed task state serialization.

Rather than serializing several messages separately, serialize one
message per app to/from the state handler.