renamed safewrite