re-engineered with vertex & template