Improve security checks on ajax calls
Fix tests