refactored isDir & processing of subdirectories into separate function
more cleanup & comments