Move lock_file, rollback, and close to tempfile