Extended write() method to handle more types.