Pulled code out of exchange_code due to unspecific errors.