finish insert code restructure