Add support for line encoding, and fix a few minor bugs.