updating insert util to be more robust