[Refactor Branch] Fixed out of memory error on logout

Fixed typo SericeS
Fixed endless loop causing an "PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted" error