Cleaned it up and added a fix for output folder creation