updated encode function to use python-slugify