some cleanup in insert functions
(not thoroughly tested yet)