Stagedriver fixes and refactoring