Code added to check order when exporting bulk insert file
SQL scripts tweaked.
Leg detecting script works.