Making encoding work with callbacks. Not completely there yet.