contract BookKeeping {
    
    struct ShareHolders {
        mapping(address => uint) ownerAddressToShares;
        uint numberOfShareHolders;
    }
    
    // _amount should be greator than 0
    function _sharesBought(ShareHolders storage _shareHolders, address _owner, uint _amount) 
    internal {
        // If user didn't have shares earlier, he is now a share holder!
        if (_shareHolders.ownerAddressToShares[_owner] == 0) {
            _shareHolders.numberOfShareHolders += 1;
        }
        _shareHolders.ownerAddressToShares[_owner] += _amount;
        
    }

    // _amount should be greator or equal to what user already have, otherwise will result in underflow
    function _sharesSold(ShareHolders storage _shareHolders, address _owner, uint _amount) 
    internal {
        _shareHolders.ownerAddressToShares[_owner] -= _amount;
        
        // if user sold all his tokens, then there is one less share holder
        if (_shareHolders.ownerAddressToShares[_owner] == 0) {
            _shareHolders.numberOfShareHolders -= 1;
        }
    }
}
// Keeps a mapping of onwerAddress to the number of shares owned
function _sharesSold(ShareHolders storage _shareHolders, address _owner, uint _amount) 
internal {
    _shareHolders.ownerAddressToShares[_owner] -= _amount;
        
    // if user sold all his tokens, then there is one less share holder
    if (_shareHolders.ownerAddressToShares[_owner] == 0) {
        _shareHolders.numberOfShareHolders -= 1;
    }
}

// _amount should be greator or equal to what user already have, otherwise will result in underflow