fixed some errors, I have no idea why redirect does not go into an infinite loop anymore, but it's fixed.