handle directories more intelligently