Six years ago, David Melendez reversed course. At loose ends after repeatedly traveling to China for business, this mid-careerist saw a bottom in the real estate market in 2012 and opted to invest in undervalued homes. But with three children near college age, he was short of cash. Where would he find it? His IRA.

Most people assume that an IRA can be kept only with a brokerage firm, such as Fidelity and Vanguard, and that its portfolio must reflect the stock or bond mutual funds they offer. But not according to the law.

Instead, it offers willing entrepreneurs like Melendez the chance to self-direct their funds in investments such as real estate or real estate investment trusts, commodities, precious metals, tax liens and a host of other options. In so doing, investors can have more control over their retirement accounts, which can be really good -- or very bad.

Get Breaking News Delivered to Your Inbox

For Melendez, it has worked out, so far. A "flipper," when the name still conjured up a dolphin show, he bought and rehabbed homes with his father in the Los Angeles area and then resold them. Given his background, Melendez felt more comfortable putting his money in real estate than in traditional stock market investments. "I had a tendency to buy and sell too often," he admitted, "so my portfolio didn't perform well."

Melendez decided to return to his roots. He began by looking locally in the Los Angeles area, then in Oregon and Utah, but finally settled on Florida, where home prices had fallen by as much as two-thirds. His strategy: pay in cash, rehab the home and then rent. And with no mortgage, most of the profit flowed to him -- but not directly. To tap into his IRA, Melendez had to follow a complicated arms-length procedure set up by the IRS.

Some accountants say the IRS views self-directed IRAs as warily as a quarterback assesses defensive linemen, which is why most professional tax preparers won't recommend them. First and foremost, an IRA is a tax-advantaged retirement account, meaning it's untaxed until the individual starts withdrawing money, either voluntarily or mandatorily. Taxes are paid on the amount withdrawn -- the same as for a 401(k) retirement account.

A self-directed IRA modifies these parameters. It allows owners to operate a tax-free business inside this retirement vehicle, giving them an edge over other small businesses that pay taxes on income, and denying the federal government its share of the profits.

But the counterargument has merits too. Why should someone with an IRA be bound to a broker, limited by the broker's investment options and have to pay a commission to that broker?

An IRS spokesperson said the agency doesn't know how many self-directed IRAs have been set up and recommended talking to the Employee Benefit Research Institute (EBRI), a Washington, D.C., nonprofit that offers research on economic issues, including retirement. EBRI didn't respond to calls and emails requesting comment. But those familiar with self-directed IRAs say they're only a small fraction of the more than 23 million IRAs in this country.

An internet search for self-directed IRAs won't take you to any major brokerage house websites. And for obvious reasons: the potential for major losses, as well as client lawsuits, and the fact that the IRS closely scrutinizes these types of accounts. Since the taxman can construe as damaging or fatal any misstep, such as investing in life insurance or rare art, major brokerages regard them as the "third rail" -- electrified and highly dangerous.

The only companies that handle these types of accounts are called "custodians." Unlike brokers, custodians don't usually offer advice, but simply hold the money and dole it out according to the customer's requests. Many of these custodian firms advise you to find an attorney familiar with setting up self-directed IRAs to avoid a financial or legal misstep.

Entrepreneurs who've worked for themselves and started a retirement account early in their careers often make good candidates. The ideal time to take advantage of a self-directed IRA is from age 30 into your early 50s. By this time, many IRA owners have accumulated a balance of more than $100,000, but still have several years before having to think about paring it down in retirement. This is important because custodians will likely assess a fee each time you move money in or out of the account.

But most important, a self-directed IRA has to be kept separate from any other investment, whether a retirement account or otherwise. No portion of it can be used to invest in another business or venture like a restaurant, a home for yourself or involve family members. If you inadvertently make a mistake, the entire self-directed IRA becomes taxable. And if it's terminated for any reason, the custodian is likely to charge an additional fee.

Melendez retained attorney Mark Kohler, who advised him on how to set up his self-directed IRA in a YouTube video. Kohler helped Melendez move a portion of his IRA to a custodian, Polycomp, while keeping some of his money in stock index funds as a backup. Then Kohler assisted Melendez in setting up a limited liability company, or LLC.

Polycomp transferred the money into the LLC, which, as its sole manager, Melendez owns and operates. It is through the LLC that Melendez invests in and runs his rental properties. He can even borrow money from banks for leverage when buying them. But Melendez is required to pay taxes on that part of his investment.

By buying these properties for cash through his LLC, renovating them himself and then renting them out, Melendez has almost tripled his money. He pays a little more than a third of his rental income in Florida taxes, maintenance and management fees. And his custodian Polycomp earns a fee of only $300 per year since most of the accounting is done through the LLC.

The money made within his self-directed IRA is tax-free, just as it would be with an IRA or 401(k), until Melendez either retires and legally has to draw it down, or disbands his LLC and moves the money back into a traditional IRA.

As for the IRS? "You'll have no problems," Melendez said, "as long as you follow the rules."