restored write() to previous form, still behaves strangely