Fixed bug, and refactored, the "exchangeandphaserdemo" application