Changed my code so that loot is only written once.