added opendir() error handling