General analysis of magnetic refrigeration and its optimization using a new concept: maximization of refrigerant capacity