More work on insert function