A mistake at the startup stage can cost you a lot of money when it comes time to raise funds or sell your business. Take it from Jamie Firsten, a partner at the business law group at Toronto’s Cassels Brock, who works with early-stage companies and venture capital firms in the growing Canadian technology sector.

Firms like Cassels Brock are now offering “startup packages” that allow companies to get legal advice and work at a fraction of the regular rate. (Fees ramp up once the company raises outside capital.) “We’re making a lot of bets,” says Firsten, who heads the firm’s technology group.

Here are four legal matters you should pay attention to in the early days.

1. Shareholder Agreements

Partnerships between co-founders are often sealed with little more than a handshake. Firsten recommends using a formal shareholders’ agreement, which sets out protocols for departures from the company and disputes within it. Otherwise, problems between partners can quickly spiral into expensive and disruptive legal action.

Firsten uses the example of three friends who started a software company, and divvied up the equity evenly. “They build an interesting product, start selling, and [the company] gains value,” he recounts. “At that point, they realize two of the partners don’t get along with each other, [and] one of them wants to leave.” The simple ownership document the trio had agreed to didn’t include a resolution mechanism, so each turned to a lawyer. Hundreds of thousands of dollars were spent. “In the meantime, they’re not making progress on their business, [so] its losing value.”

During this period, a private equity firm approached the company about a buyout. Due diligence revealed the internal tug-of-war, decreasing the valuation the buyer placed on the business. The costs of straightening out all the legal issues were also taken out of the purchase price.

Firsten became involved about nine months in, when one of the partners approached him to act as counsel for the company. But the trio proved unable to resolve their personal differences. “We ended up getting a shotgun buyout—one of the individuals took out the other two, which cost them a bunch of money to do,” Firsten recalls. “That individual held on for another six months and then sold it to the private equity firm, and we cleaned up the corporate structure in the meantime.”

2. Intellectual Property Rights

The most valuable thing in most tech companies is the intellectual property (IP). But startups don’t always give it the legal care and attention it deserves. “Early stage companies mess this up all the time,” says Firsten.

Startups that come out of incubators or academic institutions are particularly susceptible to such issues. Founders often get input or ideas from other people within that ecosystem, but neglect to get them to sign IP waivers. The shortcoming may not come to light until an investor or buyer is conducting due diligence, at which point the company must retrace its steps to get the correct documentation in place. “If you have to go back to the individual [say] three years later, that’s going to seem weird,” Firsten notes. “Maybe they’ll realize that they should ask you for something at that point.”

In instances where earlier inattention have opened a company up to possible IP disputes, investors and acquirers will often allocate the risk of such claims to the founders. That means if someone comes knocking for a payoff, you may have to tack that out of your own pocket.

Firsten recounts a recent case in which he acted on behalf of a large VC firm. The startup in question had failed to obtain all the necessary waivers, and it cost an extra $50,000 in diligence to trace back all the deals and handshake agreements it had made. “They went back to as many individuals as they could and tied up what we perceived to be the material loose ends, but at the end of the day, there was still some major risk to the deal,” he recalls. “And the VC said, ‘I’m going to cram down your valuation a little bit because of this, and in our deal documents I’m going to allocate the risk of this to you.’” (No IP claims have been made in that case, as far as Firsten is aware).

3. Options

The flourishing of Canada’s technology ecosystem is creating ever-more competition for top talent. Even the best-funded startups can’t compete with international giants on salary alone, so most compensation packages at early-stage firms are heavy on future-oriented incentives, typically stakes in the company.

Too many founders “just give equity up,” says Firsten. A better move is to offer stock options, with vesting schedules across a period of time—36 months, say—that incentivize the recipient to stay at the company, and structures that pay out based on meeting deliverables and timelines.

Mess this up, and you risk handing over a big piece of your company to the wrong person. “In one situation, instead of giving options, they gave just straight equity, and the guy left six months later,” Firsten recounts. “Now he’s sitting on the cap table”—the document that shows who owns what—“with 30%.” When the company tried to raise money from a VC firm, the errant shareholder became a point of contention. “The VC’s saying, ‘What’s going on here? This guy didn’t deliver on anything,’” Firsten says. “It shows that the founders couldn’t make good business decisions.” The deal ultimately fell apart on that basis.

4. Policies and procedures

In the freewheeling early days, rules and protocols are the last things on the minds of founders. That works just fine until the startup tries to raise outside capital, or becomes the target of an acquisition offer. “I prepare due diligence request lists for acquisitions $50 million and up, and [they say], ‘Tell me every single little thing you’ve done in your business since the day you started it. Here’s a 12-page questionnaire.’”

Carefully documenting your processes and policies from the very beginning makes it much easier to pass such an inquisition. Which protocols need to be committed to paper will depend on the nature of your business. Take cyber security. “For some businesses, those documentations or policies are not as material at the outset, because in that industry, the person investing is not going to care as much,” Firsten notes. But they may be necessary in other sectors. “If you’re building a software platform and you have a bunch of employees, you need a cyber security policy in place.”