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