Transplant large amount of code before replacing writeExtended, that is not going to work