Change write_to, fix trailing whitespaces, and some small changes.