add bound checking for materials