If there are several mortgages of equal rank or if separate amounts due to distinct persons are embraced in the same mortgage and one mortgagee forecloses, the court will control the proceeds of the sale for distribution to the several mortgagees according to their claims.