Fixes #285. Splits up header/body parts

This is a refactored implementation of #274.