DRY up mutex code