Fixed encoding bugs and a stdin reader bug.