Debugging, and more defensive dest folder fetching
Common output opening code, and add missing close
Add a license header, and switch to Apache