added 'when-head', and some reordering.