fixes to stagedriver and some refactoring