Refactored. flip_cities function added