optimize work directory guessing logic