Fix generation of contact loops