Code cleanup of write() method.