Added improved insert function