Refactored csrf, and added test case!