Add dir check and logging