changed order of sql statements in get_materials