Refactor, add output file support, custom messages

Closes #1 and #2.