Why was religion important in the middle ages