You got the what almost right, but the why completely wrong.
JFK was assassinated in a joint effort by the CIA and the Mafia.
I forget the names of the mob bosses involved (if I heard I could tell ya), but here's the basis..
JFK's dad was a U.S. ambassador and had connections with the mob in Chicago. This mob boss agreed to help get JFK elected if Bobby Kennedy would stop putting the pressure on the mob. But instead of agreeing to these terms, JFK made Bobby Attorney General, pissing this mafia leader off. And Bobby never backed down either. This was part of the Mafia's motivation.
Now for the CIA. As you all know, the Bay of Pigs invasion was a disaster, and Kennedy blamed the CIA. He felt the organization was fallible and had plans to dissolve it (as you can see with 9/11, Kennedy was right about their inefficiencies). This is what irritated the CIA, although it wasn't the deciding factor.
The deciding factor was pressure from the Mafia. Now, at this point in time, Castro was rising to power in Cuba, and when it turned out that he would be Communist, EVERYONE was unhappy. The Mafia was angry because Cuba was a big gambling spot, and Kastro wouldn't let them leech of the land, so they would be losing millions upon millions of dollars. In the past, the CIA worked in cooperation with the Mafia, and they wnated their help again to take down Kastro. The CIA wanted democracy, and the Mafia wanted to make money, so it was a perfect fit. The catch was that the Mafia despised Kennedy and wanted him out, so they threatened to reveal several Top Secret operations to the public without cooperation. Thus, the CIA felt obliged to protect the interests of the country by aiding in the cover up of the mob-related assassination of JFK.
There are reports that RFK knew that this is how it happened, but didn't go public for the same reason that the CIA covered it up... interest of the nation.
RFK was killed later during his campaign for the same reason that the Mafia didn't want to put up with more of his bullshit.
Btw, there's also a conspiracy the Marylin Monroe was assassinated by the same mob. Now as most of you know, the reported cause of death was a drug overdose. There is, however, a toxin that can be administered into the rectum that at the time was untraceable. Most of you also know that Monroe was having an affair with JFK, but most of you probably don't know that she was also having an affair with RFK. Now the mafia wanted to ruin the Kennedy's, so they figured they'd expose the affair with Bobby. So one night after Bobby left her house, two hitmen broke in, administered the toxin, threw some pills around, and hoped that the maid would spill the beans on Kennedy being there. She didn't though, because Kennedy got to her first and covered up the entire thing.