code cleanup and lock fixes
fix hmac computation