conditionally define global functions, add ddhook