Updated to use the flat_routes table
Improved spacing of code