Fix code for more recent BSON versions.

Also put the (orphan) instances in a separate module.
Add comments