Write to file and more sending logic