added writeIFExists