fixed directory error with pushd popd and reinstated cleanup code