Implement insert function