port autostager from old (private) code