Fix tests and codes
mv ensure_dir to here