Fixed some insert logic errors