Marx: Religion as a form of false consciousness

For Marx, religion is an ideology with the specific function of conserving power to the ruling class. Each major technological epoch change has a corresponding ruling class and underclass.
Religion is therefore part of false consciousness, that ideological output which distorts what should otherwise be the real intentions and strategies of the underclass. Every economic and social structure needs an ideology and produces it. So we all believe in capitalism, don't we (?) and religion has been seen as keeping people in their place.
How come? Because the poor and downtrodden were told by their preachers that if this life was tough, but they lived well and dutifully, they would have a glorious life in heaven afterwards. Moreso, if you did not behave you could end up in the hell of eternal torment. So you'd better behave yourself.
The result of such a message must be to keep the rich man in his castle and the poor man in his gate. The sociology of this ideological message, then, is social conservatism. This is what Karl Marx set out to expose. He wrote:
The class that has the means of material production at its disposal, has control at the same time over the means of mental production.
Marx, K., Engels, F. (1974), The German Ideology, Lawrence and Wishart.