safer file writes
safety first
clean up error handling