Added CSRF protection handling, courtesy of a comment by Allan Ditzel!