What role did the church have in the medieval times?