[Not tested] Perform huge giant refactoring. Remove SESSION, messages[] usage. Make parameters more explicit. Fix potential bugs.
[Not tested] Make get_cookie_part function internal parameters more explicit