Ported the "retain query through the redirect" feature. Refactored the unit tests.