Added base_dir option and cleanup codes