refactoring of workflow manager (second pass). Should be all done now.