fixed socket stuff and writes