Changed the way how materials are got

Now using our own function for it.