handle directory a bit more sanely