Finally got home to test this. Fixed another minor issue. Script now works as expected for a fresh db.