Updated insert function.