add code to handle nonexistent intermediates and create missing target dirs