generating and saving IDs