fixed the bugs of insertion function