Messing around with primary keys and loops