Added sorting to the dirnames array because that was causing problems