fixed to use closedir() instead close() when closing directories