added write binary mode