So, way back in, uh, either Samuel or Kings, David had a census and god killed a bunch of people. Turns out it wasn't so much god as Satan. Joab tries to cajole him into not holding it, but he's adamant. Turns out he has 1 million battle-ready men at his disposal, putting him right up there with modern-day Russia or North Korea, and not even including the Benjaminites or the Levites.
This pisses god off to no end, even after David apologises. God offers him a choice of three punishments: 1) a three-year famine 2) three months of being defeated by their enemies 3) three days of pestilence. David asks god to just kill him instead, so god sends the pestilence. He's up to 70 000 dead when he changes his mind and tells the angel to stop. David looks up at that point and sees the angel in the sky with a sword drawn. David points out that he's the one who sinned and asks why god killed all those innocent people.
Rather than answer, god tells him to build an alter on a threshing-floor. David goes to the owner, Ornan, and explains the situation and offers to buy it at fair market price. Ornan demurs, but David insists on paying in full. Then he sacrifices. I bet a lot of the payment went to cleaning that mess up.