Fixed a closure bug that was causin gthe wrong data to be tried to insert into wrong table