Fixes for CEP-912 and CEP-915

Fixed directory checking and race condition.