added function to write to bin file

code cleanup