function refund() {
    if (!has_token_sale_time_ended()) throw;

    if (is_min_goal_reached()) throw;
  
    if (block.number > refund_window_end_block) throw;

    var refund_amount = balances[msg.sender];

    if (refund_amount == 0) throw;

    balances[msg.sender] = 0;

    if (!msg.sender.send(refund_amount)) {
    if (!msg.sender.send(refund_amount)) throw;
    }
  }