CSRF protection, bug fixes

CSRF protection, bug fixes