Updated insertion function.