fixed and implement insert function