Refactoring. Moving directories scanning to standalone file.