improve base directory detection