function calculateToFund() internal returns (uint256) {
    uint256 cap;
    uint256 weiRaised;

    if (block.timestamp < phase2StartTime) { 
      cap = phase1MaxEtherCap;
      weiRaised = privateWeiRaised.add(phase1WeiRaised);
    } else {
      cap = phase2MaxEtherCap;
      weiRaised = phase2WeiRaised;
    }

    uint256 postWeiRaised = weiRaised.add(msg.value);

    if (postWeiRaised > cap) {
      return cap.sub(weiRaised);
    } else {
      return msg.value;
    }
  }