Refactored to support missing-target handlers, and added a modified version of @vivien's mkdir wrapper.