Added code to create output directory if none exists