Refactored SQL code that was causing multiple inserts.