Merge Alan's modification with original behaviour.