Functional testing: waiting on dir

Refactored testing code a bit