fixed readdir error checking