Updated code using sf and custom vertex / matrix