Corrected so that output folder is created if it does not exist