@wip Refactor structure to avoid multiple redirects.

Finish tests