refactor readdirs