added logic to create output directory if one doesn't exist