function sell(uint _amount, uint _price) external {
        require(0 < _price && _price < maxPrice && 0 < _amount && _amount < maxTokens && _amount <= users[msg.sender].tokens);
        commitDividend(msg.sender);
        users[msg.sender].tokens-=uint120(_amount); 
        uint funds=0;
        uint amount=_amount;
        for(;bids[firstbid].price>0 && bids[firstbid].price>=_price;){
          uint value=uint(bids[firstbid].price)*uint(bids[firstbid].amount);
          uint fee=value >> 9; 
          if(amount>=bids[firstbid].amount){
            amount=amount.sub(uint(bids[firstbid].amount));
            commitDividend(bids[firstbid].who);
            emit LogTransaction(msg.sender,bids[firstbid].who,bids[firstbid].amount,bids[firstbid].price);
            
            
            funds=funds.add(value-fee-fee);
            users[custodian].weis+=uint120(fee);
            totalWeis=totalWeis.sub(fee);
            
            users[bids[firstbid].who].tokens+=bids[firstbid].amount;
            
            uint64 next=bids[firstbid].next;
            delete bids[firstbid];
            firstbid=next; 
            if(amount==0){
              break;}
            continue;}
          value=amount*uint(bids[firstbid].price);
          fee=value >> 9; 
          commitDividend(bids[firstbid].who);
          funds=funds.add(value-fee-fee);
          emit LogTransaction(msg.sender,bids[firstbid].who,amount,bids[firstbid].price);
          
          
          users[custodian].weis+=uint120(fee);
          totalWeis=totalWeis.sub(fee);
          bids[firstbid].amount=uint96(uint(bids[firstbid].amount).sub(amount));
          require(bids[firstbid].amount>0);
          
          users[bids[firstbid].who].tokens+=uint120(amount);
          bids[firstbid].prev=0;
          totalWeis=totalWeis.sub(funds);
          (bool success, ) = msg.sender.call.value(funds)("");
          require(success);
          return;}
        if(firstbid>0){
          bids[firstbid].prev=0;}
        if(amount>0){
          uint64 ask=firstask;
          uint64 last=0;
          for(;asks[ask].price>0 && asks[ask].price<=_price;ask=asks[ask].next){
            last=ask;}
          lastask++;
          asks[lastask].prev=last;
          asks[lastask].next=ask;
          asks[lastask].price=uint128(_price);
          asks[lastask].amount=uint96(amount);
          asks[lastask].who=msg.sender;
          users[msg.sender].asks+=uint120(amount);
          emit LogSell(msg.sender,amount,_price);
          if(last>0){
            asks[last].next=lastask;}
          else{
            firstask=lastask;}
          if(ask>0){
            asks[ask].prev=lastask;}}
        if(funds>0){
          totalWeis=totalWeis.sub(funds);
          (bool success, ) = msg.sender.call.value(funds)("");
          require(success);}
    }