fixed check for failure on isdir()
fixed empty directory bug; cleaned up error messages