os.path.join and some enumerate refactoring