Fixed bugs in dir.cpp.
Improved BT code.