Edited insert logic.