write_binary function fixed.