Fixed syntax error; added ensure_dir