moved print debug outside readdir function