Changed some logic.

Altered conditional logic, moved initial directory test outside of the
loop.