moved base_dir to function