refactoring and adding check for dir in src