Refactor 'insert' function to reduce repetition

bump some gems