NEW: refactored some looped insert statements, now using a single insert instead of one per loop