Debugged index error in `addDir'
refactoring and debugging