Fixed write() implementation, was writing out 0 terminators.