moved the material fitting method into a class.