Fixed bugs, rearranged initial insert so it uses the trigger.