made generate_slugs code more robust