Use HMAC, slight refactoring