removed code duplication; switched textmode and armor=1 to binary mode; added logging to cout methods