Better directory dectection