Refactored to use CWRC-Writer as a library.