Fixed cookie check (#9) and cleaned up the redirection code.