Cleaned up exchange_details.c.

Moved a bunch of redundant code into a single function. No real
functionality changes have been made.