fixed insert function