Rewrote write.c to be faster.