added code to create output directories