Took a stab at this here in 04e824c. Feedback welcome.