function refund(uint hid, bytes32 offchain) public onlyPredictor(hid) {

                Market storage m = markets[hid]; 

                require(m.state == 1 || m.outcome == 3);
                require(now > m.reportTime);

                
                uint amt;
                amt += m.matched[msg.sender][1].stake;
                amt += m.matched[msg.sender][2].stake;
                amt += m.open[msg.sender][1].stake;
                amt += m.open[msg.sender][2].stake;

                require(amt > 0);

                
                m.matched[msg.sender][1].stake = 0;
                m.matched[msg.sender][2].stake = 0;
                m.open[msg.sender][1].stake = 0;
                m.open[msg.sender][2].stake = 0;

                if(!(trial[msg.sender].valid)) {
                        msg.sender.transfer(amt);
                } else {
                        uint trialAmt = trial[msg.sender].totalStakes[hid];
                        amt = amt - trialAmt;
                        require(amt > 0);
                        msg.sender.transfer(amt);
                }

                emit __refund(hid, offchain);
                emit __test__refund(amt);
        }