Output folder is created if it does not exist (+ some refactoring)