function to store last_used_port