add some checkers to make everything working from the first run
make the dirstack shared among terminals