some refactoring and comments, plus added check to ensure all supplied paths are directories and not files