Adding check for valid directory for easier debug