Some code shared by kake and hake.