Refactory code to use new Material class and Entity class.