In 27, Rambam describes that the purpose of the Torah's commandments is first to perfect our society so that our needs are taken care of. This allows us to achieve our primary purpose which is spiritual and intellectual perfection. In 28 Rambam describes how every teaching of the Torah teaches us one of three things; a true idea, a prohibition against actions that cause strife, or a commandment that makes us a better society.