checkDirectories logic moved to a method