fixed client side infinite redirection

this is very ugly, the entire code needs to be cleaned up