Refactoring and fixed exception when a directory name is longer