Removed cumbersome callback API for serialization. Cleaned up style.

Fixes #678