Clean up datagram structure

This includes @Hawkheart's changes (which fix issue #18), therefore this supersedes pull request #23.