Write to fd's

Bunch of other improvements