Update BackToTheIndex to use hooks

Now works with portals also, better code, uses hooks.