refactor readdirs added error support