In the beginning of my career i also had similar thoughts like "Why does the company make so much money when i am doing all the work" but while running my own business later i realized that it is not as simple. The company has a whole lot of risk and work bringing in projects and keeping everything afloat, as a programmer i did not have to worry about anything of that and only later i realized how much value that has, especially in a region where programming and consulting gigs weren't really easy to get.
Location really matters for programmer salaries. I went from a smaller european city where all there was for programmers were small software/marketing agencies to a european tech hub with a lot of startups and a booming market. My salary doubled just by changing location and living costs are still comparable and i finally feel i am getting paid what i am worth, which is still far from US standards though.