replacing wrong method for selecting last material
missing quote
adjusting midpoint calculation
finally got preview to work