Specifically stopped using the dir argument. Backport of a8fe12417f from master
a8fe12417f
Backport of ad0be620ae from master
ad0be620ae