make relative dir detection more robust