Fixed bugs with redirect loops

Bugs fixed. Functions normally