Theory of glasses