fixed error handling in directory