Code changes to fix issues #45 and #46 ( setup/teardown mechanism )